10 edge(int t
, int w
) : to(t
), weight(w
) {}
11 bool operator < (const edge
&that
) const {
12 return weight
> that
.weight
;
21 scanf("%d %d %d %d", &n
, &m
, &s
, &t
);
25 scanf("%d %d %d", &u
, &v
, &w
);
26 g
[u
].push_back(edge(v
, w
));
27 g
[v
].push_back(edge(u
, w
));
31 for (int i
=0; i
<n
; ++i
) d
[i
] = INT_MAX
;
33 priority_queue
<edge
> q
;
35 while (q
.empty() == false){
36 int node
= q
.top().to
;
37 int dist
= q
.top().weight
;
40 if (dist
> d
[node
]) continue;
43 for (int i
=0; i
<g
[node
].size(); ++i
){
44 int to
= g
[node
][i
].to
;
45 int w_extra
= g
[node
][i
].weight
;
47 if (dist
+ w_extra
< d
[to
]){
48 d
[to
] = dist
+ w_extra
;
49 q
.push(edge(to
, d
[to
]));
53 printf("Case #%d: ", C
);
54 if (d
[t
] < INT_MAX
) printf("%d\n", d
[t
]);
55 else printf("unreachable\n");